<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
use think\Cookie;
use think\jssdk;
use think\Session;

class Index extends Controller{

    public function index()
    {
        $date = Db::table("hotel")->where("type=0")->paginate(5);
        $page = $date->render();

       if(Cookie::has("username")){
        $name=Cookie::get("username")." <a href='".url('Index/cancel')."'>注销</a>";
       }else{
        $name=' <a href="'.url('Index/login').'">登录&注册</a>';
       }
        $data=Db::table("scenic_spot")->where('Agritainment',1)->paginate(6);
        $ccc= array();
        for($i=0;$i<count($data);$i++){
            $ccc[$i]['img'] = explode("/",$data[$i]["img"]);
        }
        $page = $data->render();

        $dome = Db::name('scenic_spot')->where('Agritainment',0)->paginate(6);
        $cc = array();
        for($i=0;$i<count($dome);$i++){
            $cc[$i]['img'] = explode("/",$dome[$i]["img"]);
        }
            $pge = $dome->render();
            $ass = new jssdk('wxddd2363aff49a909',"f9b63690e4c1acd765753d2ee99c46f3");
            $as=$ass->getSignPackage();
            $this -> assign('sign',$as);
        return view("Index/index", array('cc'=>$cc,'ccc'=>$ccc,"bo" => $date,"bd" => $dome,"bx"=>$data, "pge" => $pge, "page" => $page,"username"=>$name));
    }

    public function cancel(){
        Cookie::delete("username");
         return $this->index();
    }
    public function register(){

        return view("register");
    }
    public function login(){

        return view("Index/login");
    }
}
